package com.cee.service.Impl;

import com.cee.common.result.ResultCodeEnum;
import com.cee.dao.TwoTypeMapper;
import com.cee.dto.TwoTypeDTO;
import com.cee.exception.CeeException;
import com.cee.model.OneTwoType;
import com.cee.model.OneType;
import com.cee.model.TwoType;
import com.cee.service.OneTwoTypeService;
import com.cee.service.OneTypeService;
import com.cee.service.TwoTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional
public class TwoTypeServiceImpl implements TwoTypeService {

    @Autowired
    private TwoTypeMapper twoTypeMapper;


    @Autowired
    private OneTypeService oneTypeService;

    @Autowired
    private OneTwoTypeService oneTwoTypeService;

    @Override
    public List<TwoTypeDTO> getTwoTypeList() {
        return null;
    }

    @Override
    public void deleteTwoType(Integer id) {

    }

    @Override
    public void saveTwoType(TwoTypeDTO twoTypeDTO) {

        Integer oneTypeId = twoTypeDTO.getOneTypeId();
        String twoTypeName = twoTypeDTO.getTwoTypeName();

        if (StringUtils.isEmpty(twoTypeName) || oneTypeId == 0){
            throw new CeeException(ResultCodeEnum.PARAM_ERROR);
        }

        TwoType twoType = new TwoType();
        twoType.setTwoTypeName(twoTypeName);
        twoTypeMapper.insert(twoType);

        twoType.getId();


        OneTwoType oneTwoType = new OneTwoType();

        oneTwoType.setTwoTypeId(twoType.getId());
        oneTwoType.setOneTypeId(oneTypeId);

        oneTwoTypeService.saveOneTwoType(oneTwoType);


    }



}
